﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageEmployeesPage : Page
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public ManageEmployeesPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (_gm.LoginEmployee == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }
                        LayoutRoot.DataContext = _gm;
                }

                private void CreateButton_Click(object sender, RoutedEventArgs e)
                {
                        new CreateEmployeeWindow().ShowDialog();
                }

                private void UpdateButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Employee == null)
                        {
                                MessageBox.Show("请选择要编辑的员工");
                                return;
                        }
                        new UpdateEmployeeWindow().ShowDialog();
                }

                private void DeleteButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Employee == null)
                        {
                                MessageBox.Show("请选择要删除的员工");
                                return;
                        }

                        if (_gm.Employee.Level == EmployeeLevel.管理员)
                        {
                                MessageBox.Show("管理员无法删除");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除员工" + _gm.LoginEmployee.Name + "及其所属其他信息吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {

                                _gm.Employee.Delete();
                                _gm.Employees.Remove(_gm.Employee);
                                _gm.LoginEmployee = null;
                        }
                }

                private void SearchButton_Click(object sender, RoutedEventArgs e)
                {
                        MessageBox.Show("调试中");
                }

                private void SearchAllButton_Click(object sender, RoutedEventArgs e)
                {
                        MessageBox.Show("调试中");
                }

                private void SearchLeaveButton_Click(object sender, RoutedEventArgs e)
                {
                        MessageBox.Show("调试中");
                }
        }
}